package com.gridmobi.xrtb.domain.dsp.common;

import java.time.LocalDateTime;
import java.time.OffsetDateTime;
import java.util.Date;
import java.util.Optional;

public class OpenApiParamDTO{

    /**
     * 页码
     */
    private Integer page = 1;
    /**
     * 每页数量
     */
    private Integer size = 10;
    /**
     * 排序条件 如 id desc 或者 id desc  ,time asc
     */
    private String orderby;
    /**
     * 时间戳查询 开始时间
     */
    private Date start;
    /**
     * 时间戳查询 结束时间
     */
    private Date end;

    private Integer state;

    private Integer delstate;


    public OpenApiParamDTO(Integer page, Integer size, String orderby, Date start, Date end, Integer state, Integer delstate) {
        this.page = page;
        this.size = size;
        this.orderby = orderby;
        this.start = start;
        this.end = end;
        this.state = state;
        this.delstate = delstate;
    }


    public OpenApiParamDTO(Integer page, Integer size, Date start, Date end, Integer state, Integer delstate) {
        this.page = page;
        this.size = size;
        this.start = start;
        this.end = end;
        this.state = state;
        this.delstate = delstate;
    }


    public Integer getPage() {
        return page;
    }

    public void setPage(Integer page) {
        this.page = page;
    }

    public Integer getSize() {
        return size;
    }

    public void setSize(Integer size) {
        this.size = size;
    }

    public String getOrderby() {
        return orderby;
    }

    public void setOrderby(String orderby) {
        this.orderby = orderby;
    }

    public Date getStart() {
        return start;
    }

    public void setStart(Date start) {
        this.start = start;
    }

    public Date getEnd() {
        return end;
    }

    public void setEnd(Date end) {
        this.end = end;
    }

    public Integer getState() {
        return state;
    }

    public void setState(Integer state) {
        this.state = state;
    }

    public Integer getDelstate() {
        return delstate;
    }

    public void setDelstate(Integer delstate) {
        this.delstate = delstate;
    }

    public OpenApiParamDTO() {
    }


    public Date getStart(boolean nonNull) {
        return Optional.ofNullable(start).orElse(Date.from(LocalDateTime.now().plusDays(-1).toInstant(OffsetDateTime.now().getOffset())));
    }

    public Date getEnd(boolean nonNull) {
        return Optional.ofNullable(end).orElse(new Date());
    }

}
